<template>
	<view class="backview">
		<lexiconNavVue title="英语词库" />
		<view class="top-menu">
		</view>
		<scroll-view class="words-scroll" :style="{ height: scrollHeight + 'px'}" scroll-y
			:scroll-with-animation='true'>
			<view class="lexIcon-back">
				<block v-for="(item,index) in productList" :key="index">
					<lexIconCell :courseData="item" rightStr="GO" :dataIndex="index" @wordClicked="wordClicked">
					</lexIconCell>
				</block>
			</view>
		</scroll-view>
		<popPromptBox v-if="showPromptbox" :msg="PromptMsg" @confirm="hidePromptbox"></popPromptBox>
	</view>
</template>

<script>
	import lexIconCell from '../../components/lexIconCom/lexIconCell.vue'
	export default {
		components: {
			lexIconCell
		},
		data() {
			return {
				showPromptbox: false,
				scrollHeight: uni.getSystemInfoSync().windowHeight,
				menuIndex: 0,
				productList: []
			}
		},
		onLoad(options) {
			this.wordModel = JSON.parse(options.wordModel);
			this.navTitle = this.wordModel.title;
			this.getWordListData();
		},
		onReady() {
			const that = this
			uni.createSelectorQuery().select('.top-menu').boundingClientRect(rect => {
				that.scrollHeight = uni.getSystemInfoSync().windowHeight - rect.bottom;
			}).exec();
		},
		methods: {
			hidePromptbox() {
				this.showPromptbox = false;
			},
			getWordListData() {
				let activityTypeCode = 1;
				if (this.wordModel.dictValue == 'itso_champion_thesaurus') {
					activityTypeCode = this.$statusCode.activityItsoType;
				} else {
					activityTypeCode = this.$statusCode.activityType;
				}
				this.$http.getAppletsProductList({
					activityType: activityTypeCode,
					subTypeCategory: this.wordModel.dictValue
				}).then(res => {
					if (res.code === 200) {
						this.productList = res.data
					}
				})
			},
			wordClicked(selectIndex) {
				const selectData = this.productList[selectIndex];
				console.log('selectData', selectData);
				if (selectData.isExpired == 1) { // 未购买去获取产品详情
					this.showPromptbox = true;
					this.PromptMsg = this.$statusCode.payPopMessage;
				} else {
					if (selectData.flag == 'LANGUAGE_ORIGIN') {
						uni.navigateTo({
							url: '/pages/lexicon/wordCategoryList',
						})
					} else if (selectData.flag == 'Itso_Primary_School') {
						uni.navigateTo({
							url: '/pages/lexicon/thesaurusPrimaryGroupList?wordModel=' + JSON
								.stringify(selectData),
						})
					} else {
						uni.navigateTo({
							url: '/pages/lexicon/lexWordList?wordModel=' + JSON.stringify(selectData) +
								'&wordType=' +
								'product',
						})
					}
				}
			}
		}
	}
</script>

<style lang="less">
	.backview {
		width: 100%;
		height: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		top: 0;
		right: 0;
		background: #fff7dd;
	}

	.top-menu {
		width: 90%;
		margin-left: 5%;
		height: 5px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-around;
	}

	.menuclass {
		width: 90px;
		height: 28px;
		margin-top: 8px;
		line-height: 28px;
		border-radius: 5px;
		background: #000;
		font-size: 13px;
		font-weight: 900;
		text-align: center;
		color: white;
	}

	.activeClass {
		width: 90px;
		height: 28px;
		line-height: 28px;
		border-radius: 5px;
		background: #e7e7e7;
		font-size: 13px;
		font-weight: 900;
		text-align: center;
		color: black;
		box-shadow: 0px 5px 0px 0px rgba(204, 204, 204, 1);
	}

	.lexIcon-back {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-bottom: 20px;
	}
</style>